home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / rpclib / svc_auth.c < prev    next >
C/C++ Source or Header  |  1994-03-09  |  4KB  |  121 lines

  1. /*
  2.  * $Id: svc_auth.c,v 1.2 1993/11/10 02:47:17 jraja Exp $
  3.  *
  4.  * $Log: svc_auth.c,v $
  5.  * Revision 1.2  1993/11/10  02:47:17  jraja
  6.  * Fixed includes (added sys/param.h) + ANSI prototypes.
  7.  *
  8.  */
  9. #if !defined(lint) && defined(SCCSIDS)
  10. static char sccsid[] = "@(#)svc_auth.c    2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
  11. #endif
  12. /*
  13.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  14.  * unrestricted use provided that this legend is included on all tape
  15.  * media and as a part of the software program in whole or part.  Users
  16.  * may copy or modify Sun RPC without charge, but are not authorized
  17.  * to license or distribute it to anyone else except as part of a product or
  18.  * program developed by the user.
  19.  * 
  20.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  21.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  22.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  23.  * 
  24.  * Sun RPC is provided with no support and without any obligation on the
  25.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  26.  * modification or enhancement.
  27.  *
  28.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  29.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  30.  * OR ANY PART THEREOF.
  31.  *
  32.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  33.  * or profits or other special, indirect and consequential damages, even if
  34.  * Sun has been advised of the possibility of such damages.
  35.  *
  36.  * Sun Microsystems, Inc.
  37.  * 2550 Garcia Avenue
  38.  * Mountain View, California  94043
  39.  */
  40.  
  41. /*
  42.  * svc_auth_nodes.c, Server-side rpc authenticator interface,
  43.  * *WITHOUT* DES authentication.
  44.  *
  45.  * Copyright (C) 1984, Sun Microsystems, Inc.
  46.  */
  47.  
  48. #include <sys/param.h>
  49. #include <rpc/rpc.h>
  50.  
  51. /*
  52.  * svcauthsw is the bdevsw of server side authentication. 
  53.  * 
  54.  * Server side authenticators are called from authenticate by
  55.  * using the client auth struct flavor field to index into svcauthsw.
  56.  * The server auth flavors must implement a routine that looks  
  57.  * like: 
  58.  * 
  59.  *    enum auth_stat
  60.  *    flavorx_auth(rqst, msg)
  61.  *        register struct svc_req *rqst; 
  62.  *        register struct rpc_msg *msg;
  63.  *
  64.  */
  65.  
  66. enum auth_stat _svcauth_null();        /* no authentication */
  67. enum auth_stat _svcauth_unix();        /* unix style (uid, gids) */
  68. enum auth_stat _svcauth_short();    /* short hand unix style */
  69.  
  70. static struct {
  71.     enum auth_stat (*authenticator)(struct svc_req *, struct rpc_msg *);
  72. } svcauthsw[] = {
  73.     _svcauth_null,            /* AUTH_NULL */
  74.     _svcauth_unix,            /* AUTH_UNIX */
  75.     _svcauth_short,            /* AUTH_SHORT */
  76. };
  77. #define    AUTH_MAX    2        /* HIGHEST AUTH NUMBER */
  78.  
  79.  
  80. /*
  81.  * The call rpc message, msg has been obtained from the wire.  The msg contains
  82.  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
  83.  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
  84.  * does the following things:
  85.  * set rqst->rq_xprt->verf to the appropriate response verifier;
  86.  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
  87.  *
  88.  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
  89.  * its length is set appropriately.
  90.  *
  91.  * The caller still owns and is responsible for msg->u.cmb.cred and
  92.  * msg->u.cmb.verf.  The authentication system retains ownership of
  93.  * rqst->rq_client_cred, the cooked credentials.
  94.  *
  95.  * There is an assumption that any flavour less than AUTH_NULL is
  96.  * invalid.
  97.  */
  98. enum auth_stat
  99. _authenticate(rqst, msg)
  100.     register struct svc_req *rqst;
  101.     struct rpc_msg *msg;
  102. {
  103.     register int cred_flavor;
  104.  
  105.     rqst->rq_cred = msg->rm_call.cb_cred;
  106.     rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
  107.     rqst->rq_xprt->xp_verf.oa_length = 0;
  108.     cred_flavor = rqst->rq_cred.oa_flavor;
  109.     if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
  110.         return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
  111.     }
  112.  
  113.     return (AUTH_REJECTEDCRED);
  114. }
  115.  
  116. enum auth_stat
  117. _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg)
  118. {
  119.     return (AUTH_OK);
  120. }
  121.